package cn.edu.scau.cmi.linpeiwei.composite.safe;

import java.util.ArrayList;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class SafeComposite extends SafeComponent {
	
	private String name;
	private ArrayList<SafeComponent> nodeList = new ArrayList<>();

	public SafeComposite(String name) {
		// TODO 自动生成的构造函数存根
		this.name = name;
	}
	@Override
	public String getName() {
		// TODO 自动生成的方法存根
		return name;
	}

	public boolean add(SafeComponent sc) {
		return nodeList.add(sc);
	}

	public boolean delete(SafeComponent sc) {
		return nodeList.remove(sc);
	}

	public SafeComponent getChild(int index) {
		if(index < nodeList.size() && index >= 0)
			return nodeList.get(index);
		return null;
	}
	public ObservableList<String> getList(){
		ObservableList<String> list = FXCollections.observableArrayList();
		for(int i = 0; i < nodeList.size(); i++) {
			list.add(nodeList.get(i).getName());
		}
		return list;
	}
	public String toString() {
		return name + "(树枝)";
	}

}
